package BookSystem.operation;

import BookSystem.book.Book;
import BookSystem.book.BookList;

import java.util.Scanner;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 */
public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.print("请输入要归还的书籍: ");
        Scanner in = new Scanner(System.in);
        String name = in.nextLine();
        int currentSize = bookList.getUseSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)
             && book.isBorrowed()){
                book.setBorrowed(false);
                System.out.println("归还成功！");
                return;
            }
        }
        System.out.println("不需要归还！");
    }
}
